using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

using Jeffrey.XFramework;
using Jeffrey.XFramework.XCrawl;

namespace Jeffrey.XProcess
{
    public class ImagesFilter : Filter
    {
        public  static readonly String IMAGES = @"bmp|gif|jpe?g|png|tiff?";
        private static readonly String IMAGES_EXTENSIONS = @".+\.(" + IMAGES + @")$"; //RegexOptions.IgnoreCase

        public ImagesFilter(String name, String classname, String path)
            : base(name, classname, path) { }
        public ImagesFilter(String name, String description, String classname, String path)
            : base(name, description, classname, path) { }

        protected override bool innerAccepts(CrawlUri uri)
        {
            String scheme = uri.Scheme;
            if (scheme != "http")
                return false;

            Regex extends = new Regex(IMAGES_EXTENSIONS, RegexOptions.IgnoreCase);
            return extends.Match(uri.AbsolutePath).Success;
        }
    }
}
